//
//  WbTextView.swift
//  Weibo
//
//  Created by HH on 16/12/10.
//  Copyright © 2016年 Weibo. All rights reserved.
//

import UIKit
import SnapKit

class WbComposeTextView: UITextView {
    
    lazy private var placehoderLabel:UILabel = {
       
        let label = UILabel(text: "分享新鲜事...", font: 13, textColor: UIColor.lightGray)
        
        return label
        
    }()
    
    override var font: UIFont?{
        
        didSet{
            
            if font != nil{
                
                placehoderLabel.font = font
            }
        }
        
    }
    
    
    
    
    override init(frame: CGRect, textContainer: NSTextContainer?) {
        super.init(frame: frame, textContainer: textContainer)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func setupUI() {
        
        addSubview(placehoderLabel)
        
        placehoderLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(3)
            make.top.equalToSuperview().offset(marign)
        }
        
        NotificationCenter.default.addObserver(forName: NSNotification.Name.UITextViewTextDidChange, object: nil, queue: OperationQueue.main) { (_) in
            
            self.placehoderLabel.isHidden = self.hasText
        }
        
    }
    
    deinit {
        
    }

}
